package com.example.lenovo.a32ui;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button mButtonToTextViewTest;
    private Button mButtonToEditTextTest;
    private Button mButtonToImageViewTest;
    private Button mButtonToProgressBarTest;
    private Button mButtonToShowAlertDialog;
    private Button mButtonToShowProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mButtonToTextViewTest = (Button)findViewById(R.id.btn_toTextViewTest);
        mButtonToEditTextTest = (Button) findViewById(R.id.btn_toEditTextTest);
        mButtonToImageViewTest = findViewById(R.id.btn_toImageViewTest);
        mButtonToProgressBarTest = findViewById(R.id.btn_toProgressBarTest);
        mButtonToShowAlertDialog = findViewById(R.id.btn_toShowAlertDialog);
        mButtonToShowProgressDialog = findViewById(R.id.btn_toShowProgressDialog);

        mButtonToTextViewTest.setOnClickListener(this);
        mButtonToEditTextTest.setOnClickListener(this);
        mButtonToImageViewTest.setOnClickListener(this);
        mButtonToProgressBarTest.setOnClickListener(this);
        mButtonToShowAlertDialog.setOnClickListener(this);
        mButtonToShowProgressDialog.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.btn_toTextViewTest: {
                Intent intent = new Intent(this,TextViewTest.class);
                startActivity(intent);
                break;
            }
            case R.id.btn_toEditTextTest: {
                Intent intent = new Intent(this,EditTextTest.class);
                startActivity(intent);
                break;
            }
            case R.id.btn_toImageViewTest: {
                Intent intent = new Intent("homework.ImageViewTest");
                startActivity(intent);
                break;
            }
            case R.id.btn_toProgressBarTest: {
                Intent intent = new Intent(this,ProgressBarTest.class);
                startActivity(intent);
                break;
            }
            case R.id.btn_toShowAlertDialog: {

                //使用AlertDialog组件

                AlertDialog.Builder dialog = new AlertDialog.Builder(this);

                dialog.setTitle("this is a AlertDialog");
                dialog.setMessage("Hello World");
                dialog.setCancelable(false);

                //为AlertDialog界面添加OK按钮   hint:注意使用的方法名
                dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });

                //为AlertDialog界面添加Cancel按钮   hint:注意使用的方法名
                dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });

                dialog.show();
                break;
            }
            case R.id.btn_toShowProgressDialog: {

                //创建ProgressDialog实例对象
                ProgressDialog progressDialog = new ProgressDialog(this);

                //对ProgressDialog实例对象做一些初始化
                progressDialog.setTitle("this is ProgressDialog");
                progressDialog.setMessage("Loading...");
                progressDialog.setCancelable(true);
                progressDialog.show();

                break;
            }

            default:
        }
    }
}
